package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dkd.manage.domain.dto.HostelAssignmentsDTO;
import com.dkd.manage.domain.vo.HostelAssignmentsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.HostelAssignments;
import com.dkd.manage.service.IHostelAssignmentsService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 宿舍分配管理Controller
 * 
 * @author czq
 * @date 2024-11-09
 */
@RestController
@RequestMapping("/manage/assignments")
public class HostelAssignmentsController extends BaseController
{
    @Autowired
    private IHostelAssignmentsService hostelAssignmentsService;

    /**
     * 查询宿舍分配管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:assignments:list')")
    @GetMapping("/list")
    public TableDataInfo list(HostelAssignmentsDTO hostelAssignmentsDTO)
    {
        startPage();
        List<HostelAssignmentsVo> voList = hostelAssignmentsService.selectHostelAssignmentsVoList(hostelAssignmentsDTO);
        return getDataTable(voList);
    }

    /**
     * 导出宿舍分配管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:assignments:export')")
    @Log(title = "宿舍分配管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HostelAssignments hostelAssignments)
    {
        List<HostelAssignments> list = hostelAssignmentsService.selectHostelAssignmentsList(hostelAssignments);
        ExcelUtil<HostelAssignments> util = new ExcelUtil<HostelAssignments>(HostelAssignments.class);
        util.exportExcel(response, list, "宿舍分配管理数据");
    }

    /**
     * 获取宿舍分配管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:assignments:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hostelAssignmentsService.selectHostelAssignmentsById(id));
    }

    /**
     * 新增宿舍分配管理
     */
    @PreAuthorize("@ss.hasPermi('manage:assignments:add')")
    @Log(title = "宿舍分配管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HostelAssignmentsDTO hostelAssignmentsDTO)
    {
        return toAjax(hostelAssignmentsService.insertHostelAssignments(hostelAssignmentsDTO));
    }

    /**
     * 修改宿舍分配管理
     */
    @PreAuthorize("@ss.hasPermi('manage:assignments:edit')")
    @Log(title = "宿舍分配管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HostelAssignmentsDTO hostelAssignmentsDTO)
    {
        return toAjax(hostelAssignmentsService.updateHostelAssignments(hostelAssignmentsDTO));
    }

    /**
     * 删除宿舍分配管理
     */
    @PreAuthorize("@ss.hasPermi('manage:assignments:remove')")
    @Log(title = "宿舍分配管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hostelAssignmentsService.deleteHostelAssignmentsByIds(ids));
    }
}
